package com.krediti.entity;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import org.hibernate.validator.Length;
import org.hibernate.validator.NotNull;
import org.hibernate.validator.Range;

@Entity
@Table(name = "KORISNIK")
public class Korisnik implements java.io.Serializable {

	/**
	 * Generated serial version.
	 */
	private static final long serialVersionUID = 2892584588227880135L;

	private Integer id;
	private String jmbg;
	private String ime;
	private String prezime;
	private String adresa;
	private Integer ptt;
	private String mesto;
	private String drzava;
	private String username;
	private String password;
	private Set<KreditniZahtev> kreditniZahtev = new HashSet<KreditniZahtev>(0);

	public Korisnik() {
	}

	public Korisnik(Integer id, String jmbg) {
		this.id = id;
		this.jmbg = jmbg;
	}

	public Korisnik(Integer id, String jmbg, String ime, String prezime,
			String adresa, Integer ptt, String mesto, String drzava,
			String username, String password, Set<KreditniZahtev> kreditniZahtev) {
		this.id = id;
		this.jmbg = jmbg;
		this.ime = ime;
		this.prezime = prezime;
		this.adresa = adresa;
		this.ptt = ptt;
		this.mesto = mesto;
		this.drzava = drzava;
		this.username = username;
		this.password = password;
		this.kreditniZahtev = kreditniZahtev;
	}

	@Id
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "KORISNIK_SEQ")
	@SequenceGenerator(name = "KORISNIK_SEQ", sequenceName = "KORISNIK_SEQ")
	@Column(name = "ID", unique = true, nullable = false)
	@NotNull
	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	@Column(name = "JMBG", nullable = false)
	@NotNull
	
	@Length(min=13, max=13, message= "#{messages['JMBG must have 13 characters.']}" ) 
	public String getJmbg() {
		return this.jmbg;
	}

	public void setJmbg(String jmbg) {
		this.jmbg = jmbg;
	}

	@Column(name = "IME", length = 20)
	@Length(min=2, max = 20)
	@NotNull
	public String getIme() {
		return this.ime;
	}

	public void setIme(String ime) {
		this.ime = ime;
	}

	@Column(name = "PREZIME", length = 30)
	@Length(min=2, max = 30)
	public String getPrezime() {
		return this.prezime;
	}

	public void setPrezime(String prezime) {
		this.prezime = prezime;
	}

	@Column(name = "ADRESA", length = 100)
	@Length(max = 50)
	public String getAdresa() {
		return this.adresa;
	}

	public void setAdresa(String adresa) {
		this.adresa = adresa;
	}

	@Column(name = "PTT")
	@Range(min=10000, max=99999) 
	public Integer getPtt() {
		return this.ptt;
	}

	public void setPtt(Integer ptt) {
		this.ptt = ptt;
	}

	@Column(name = "MESTO", length = 50)
	@Length(max = 50)
	public String getMesto() {
		return this.mesto;
	}

	public void setMesto(String mesto) {
		this.mesto = mesto;
	}

	@Column(name = "DRZAVA", length = 50)
	@Length(max = 50)
	public String getDrzava() {
		return this.drzava;
	}

	public void setDrzava(String drzava) {
		this.drzava = drzava;
	}

	@Column(name = "USERNAME", length = 50)
	@Length(min=20, max = 20)
	public String getUsername() {
		return this.username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	@Column(name = "PASSWORD", length = 50)
	@Length(min=20, max = 20)
	public String getPassword() {
		return this.password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "korisnik")
	public Set<KreditniZahtev> getKreditniZahtev() {
		return this.kreditniZahtev;
	}

	public void setKreditniZahtev(Set<KreditniZahtev> kreditniZahtev) {
		this.kreditniZahtev = kreditniZahtev;
	}

}
